<script setup lang="ts">
const arr = [
  { id: 1, name: 'aaa' },
  { id: 2, name: 'bbb' }
]

// 非空断言 TS
// 变量!.属性   断言变量一定是有值,一定不为null 或者undefined
const findItem = (id: number) => {
  const findResult = arr.find(item => item.id === id)
  console.log(findResult!.name)
}
</script>

<template>
  <div class="app-page">
    <ul>
      <li v-for="(item, index) in arr" :key="index" @click="findItem(item.id)">
        {{ item.name }}
      </li>
    </ul>
  </div>
</template>

<style lang="scss" scoped></style>
